/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.dao;

import java.util.ArrayList;
import java.util.List;

import net.iwsh.core.db.DBExecutor;
import net.iwsh.core.db.connection.ConnectionFactory;
import net.iwsh.core.db.connection.provider.ConnectionProvider;

import com.us.usws.common.EpServerConstants;
import com.us.usws.model.domain.epserver.EpMscServerInfo;

/**
 * DAO class
 * @author robot
 */
public class EpMscInfoDAO {

	/**
	 * Query SQLs
	 */

	private static final String SQL_GET_MISC_INFO_BY_ROLE = "select * from msc_info where role = ?";
	private static final String SQL_GET_MISC_INFO_IN_ROLE_PREFIX = "select * from msc_info where role in (";
	private static final String SQL_GET_MISC_INFO_IN_ROLE_SUFFIX = ")";

	/**
	 * DBExeutor
	 */
	private ConnectionProvider cp = ConnectionFactory.getInstance().getProvider(EpServerConstants.EP_DB_CONN);
	private DBExecutor dbe = new DBExecutor(cp);

	/**
	 * get meeting server info by role
	 * @param role
	 * @return
	 */
	public EpMscServerInfo getMscServerInfoByRole(int role) {
		return dbe.load(SQL_GET_MISC_INFO_BY_ROLE, EpMscServerInfo.class, role);
	}

	/**
	 * get server info in roles
	 * @param roles
	 * @return
	 */
	public List<EpMscServerInfo> getMscServerInfoInRole(int... roles) {
		List<EpMscServerInfo> ret = new ArrayList<EpMscServerInfo>();
		if (roles.length > 0) {
			StringBuilder sql = new StringBuilder(SQL_GET_MISC_INFO_IN_ROLE_PREFIX);
			for (int i : roles) {
				sql.append(i).append(',');
			}
			sql.deleteCharAt(sql.length() - 1);
			sql.append(SQL_GET_MISC_INFO_IN_ROLE_SUFFIX);
			ret = dbe.list(sql.toString(), EpMscServerInfo.class, roles);
		}
		return ret;
	}
}